import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from './utils/http'
import VueAxios from 'vue-axios'
import './css/index.css'
// iconFont
import './utils/icon'

// 登录守卫
const account = window.localStorage.getItem('account')
const query = JSON.parse(decodeURIComponent(account))
if (query) {
    store.dispatch('getUser', { http: axios, query })
}

router.beforeEach((to, _, next) => {
    if (!store.state.user) {
        if (to.name === 'login' || to.name === 'register') {
            next()
        } else {
            router.replace('login')
        }
        return
    }
    next()
})

createApp(App).use(store).use(router).use(VueAxios, axios).mount('#app')
